﻿
@model PagedList<View_Member>
@{
    ViewBag.Title = "会员列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";


    AccountListModel paramModel = new AccountListModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (AccountListModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("accountlist", "account")" method="get">
    <div class="form_query">

        <div>
            <info style="float:left;">业务员账号：</info>
            <div id="manager_name"></div>&nbsp;
        </div>
        <div>
            代购编号：
            <input type="text" name="replace_buyer_NO" id="replace_buyer_NO" class="abc input-default" placeholder="" value="@paramModel.replace_buyer_NO">&nbsp;
        </div>
        <div>
            手机号：
            <input type="text" name="account_mobile" id="account_mobile" class="abc input-default" placeholder="" value="@paramModel.account_mobile">&nbsp;
        </div>
        <div>
            会员名称：
            <input type="text" name="member_name" id="member_name" class="abc input-default" placeholder="" value="@paramModel.member_name">&nbsp;
        </div>
        <div>
            会员状态：
            <select id="account_status" name="account_status">
                <option value="-10" @(paramModel.account_status == -10 ? "selected" : "")>全部状态</option>
                @{
                    dc = new Dictionary<string, string>();
                    var list = YiYiTong.Rocket.Helper.EnumHelper.GetEnumItems(typeof(AccountStatus));
                    foreach (var item in list)
                    {
                        dc.Add(item.Value.ToString(), item.Description);
                    }
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.account_status.ToString());
            </select>&nbsp;
        </div>
        <div>
            会员等级：
            <select id="member_level" name="member_level">
                <option value="-10">全部等级</option>
                @{
                    dc = new Dictionary<string, string>();
                    dbcontext.ADZ_MemberLevelConfig.ToList().ForEach(t =>
                    {
                        dc.Add(t.member_level.ToString(), t.member_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.member_level.ToString())
            </select>&nbsp;
        </div>
        <div>
            注册时间：
            <input type="text" name="beg_time" class="calendar" id="beg_time" value="@paramModel.beg_time.ToString(2)"> - <input type="text" name="end_time" class="calendar" id="end_time" value="@paramModel.end_time.ToString(2)">&nbsp;
        </div>
        <div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp;<button type="button" class="btn btn-primary" id="downloadexcel">下载表格</button>
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
            <th style="width:60px">会员头像</th>
            <th>代购编号</th>
            <th>手机号</th>
            <th>会员名称</th>
            <th>会员等级</th>
            <th>会员状态</th>
            <th>注册时间</th>
            <th>余额</th>
            <th>代购比例</th>
            <th>推荐比例</th>
            <th>加价比例</th>
            <th>业务员</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    <input type="checkbox" name="cbx_last" value="@m.uid" />@m.uid
                </td>
                <td style="text-align:center;vertical-align:middle;"><img src="@(string.IsNullOrWhiteSpace(m.logo_img_url) ? ConfigHelper.AppSetting<string>("headUrl") : m.logo_img_url )?x-oss-process=style/30_" /></td>
                <td>@m.replace_buyer_NO</td>
                <td>@m.account_mobile</td>
                <td>@m.member_name</td>
                <td>
                    @m.member_level_name
                    <a href="@Url.Action("uplevel", "account", new { uid = m.uid })">提升等级</a>

                    @{
                        if (m.member_level > 0)
                        {
                            var invite = dbcontext.ADZ_InviteCode.FirstOrDefault(t => t.rel_uid == m.uid);
                            if (invite != null)
                            {
                                var inviteinfo = dbcontext.ADZ_MemberMaster.FirstOrDefault(t => t.uid == invite.uid);
                                if (inviteinfo != null)
                                {
                                    <br /><info>推荐人：@inviteinfo.member_name @inviteinfo.account_mobile</info>
                                }
                            }
                        }
                    }

                </td>
                <td>
                    @switch (m.account_status)
                    {
                        case 0:
                            @:<div class="green">正常</div>
                            break;
                        case 9:
                            @:<div class="red">停用</div>
                            break;
                    }
                </td>
                <td>@m.create_time.ToString(1)</td>
                <td>@m.account_balance</td>
                <td>@m.buyer_rate</td>
                <td>@m.recommend_rate</td>
                <td>@m.add_rate</td>
                <td>
                    @{
                        YiYiTong.Rocket.Entity.UserInfo managerinfo = new YiYiTong.Rocket.Entity.UserInfo();
                        bool bind = false;
                        if (m.manage_uid.HasValue && m.manage_uid.Value > 0)
                        {
                            managerinfo = UserBiz.Instance.GetUserInfoById(m.manage_uid.Value);
                            if (managerinfo != null)
                            {
                                bind = true;
                                <info class="green">@managerinfo.realName</info>
                            }
                        }
                        if (!bind)
                        {
                            <info class="red">未绑定</info>
                        }
                    }
                </td>
                <td>
                    @switch (m.account_status)
                    {
                        case 0:
                            <a href="javascript:void(0);" onclick="toForbidden(@m.uid)">禁用</a>
                            break;
                        case 9:
                            <a href="javascript:void(0);" onclick="toEnable(@m.uid)">启用</a>
                            break;
                    }
                    <a href="@Url.Action("defailinfo", "account", new { uid = m.uid })" class="openbasetab">会员详情</a>
                    <a href="@Url.Action("amountloglist", "account", new { uid = m.uid })">资金明细</a>
                    @if (m.invite_limit > 0)
                    {
                        <a href="@Url.Action("invitecodelist", "account", new { uid = m.uid })">邀请码</a>
                        <a href="@Url.Action("BuildCodePage", "account", new { uid = m.uid })">生成邀请码</a>
                    }
                </td>
            </tr>
        }
        <tr>
            <td colspan="20">
                <a href="javascript:void(0);" onclick="modifymanager()">更改业务员</a>
                <a href="javascript:void(0);" onclick="deletemanager()">清空业务员</a>
            </td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]  |  总余额：@ViewData["AllBalance"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>

<script>
    reloadHandler = function () {
        window.location.reload();
    }
    function getNewLinkValue(RealName, UID) {
        var ids = getCheckboxList();
        var url = "@Url.Action("BindManager", "Account")";
        var parameter = {
            ids: ids,
            manager_uid: UID
        };
        $.post(url, parameter, function (result) {
            ShowActionResult(result, reloadHandler);
        });
    }
    function modifymanager() {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择调整的用户", 'warning');
            return;
        }
        window.open('/Common/SelectManagerUser?RoleId=4', '', 'height=570px,width=850px,fullscreen=no,resizable=no,scrollbars=no,location=no,status=no,top=50,left=250')
    }
    function deletemanager() {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择移除的用户", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要移除这些用户的业务员吗?',
            icon: 'question',
            buttons: [
                {
                    text: '确定',
                    elCls: 'button button-primary',
                    handler: function () {
                        url = "@Url.Action("UnBindManager", "Account")";
                        var parameter = {
                            ids: ids,
                            manager_uid: UID
                        };
                        $.post(url, parameter, function (result) {
                            ShowActionResult(result, reloadHandler);
                        });
                        this.close();
                    }
                },
                {
                    text: '取消',
                    elCls: 'button',
                    handler: function () {
                        this.close();
                    }
                }
            ]
        });
    }
    function toForbidden(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该账户禁用吗?',
            icon: 'question',
            buttons: [
                {
                    text: '确定',
                    elCls: 'button button-primary',
                    handler: function () {
                        url = "@Url.Action("ToForbidden", "Account")";
                                parameter = { uid: id };
                      $.post(url, parameter, function (result) {
                                    ShowActionResult(result, reloadHandler);
                                });
                                this.close();
                            }
                        },
              {
                            text: '取消',
                  elCls: 'button',
                  handler: function () {
                                this.close();
                            }
                        }

            ]
        });
    }
    function toEnable(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该账户启用吗?',
            icon: 'question',
            buttons: [
                {
                text: '确定',
                elCls: 'button button-primary',
                handler: function () {
                    url = "@Url.Action("ToEnable", "Account")";
                    parameter = { uid: id };
                $.post(url, parameter, function (result) {
                        ShowActionResult(result, reloadHandler);
                    });
                    this.close();
                }
                },
            {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                                this.close();
              }
            }

            ]
        });
    }

    BUI.use('bui/select', function (Select) {
        var manager_name = '@paramModel.manager_name';

        $.post('@Url.Action("getmanager", "common")', { selectType: 2 }, function (result) {
            var suggest = new Select.Suggest({
                render: '#manager_name',
                name: 'manager_name',
                data: result
            });
            suggest.render();
            $("input[name='manager_name']").val(manager_name);
            $("input[name='manager_name']").attr("autocomplete", "off");
        });
    });

    //下载列表
    $("#downloadexcel").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("DownAccountList", "account")");
        $("#S_Form").submit();
    });
</script>

